package generadorDescriptores.dom;

import generadorDescriptores.AttributesData;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class DimensionPropertyDom {
	Element elementDimensionProperty;
	Document document;  
	
	public DimensionPropertyDom(Document doc){
		this.document = doc;
		this.elementDimensionProperty = doc.createElement("property");
	}
	
	public void setCommonAttributes(String name, String table, String column, String label){
		Element elem = this.elementDimensionProperty;
		elem.setAttribute("name", name);
		elem.setAttribute("table", table);
		elem.setAttribute("column", column);
		elem.setAttribute("label", label);
	}
	
	public void setAttributeFunction(String function){
		if(function != null && !function.equals(""))
			this.elementDimensionProperty.setAttribute("function", function);
	}
	
	public void setAttributeType(String type){
		if(type != null && !type.equals(""))
			elementDimensionProperty.setAttribute("type", type);
	}
	
	public void setAttributeDefault(String default_p){
		if(default_p != null && !default_p.equals(""))
			elementDimensionProperty.setAttribute("default", default_p);
	}
	
	public Element getElement(){
		return this.elementDimensionProperty;
	}
	
	public void setAttributes(AttributesData data){
		this.setCommonAttributes(data.getPropName(), data.getPropTable(), data.getPropColumn(), data.getPropLabel());
		if(data.getPropDefault()!=null){
			this.setAttributeDefault(data.getPropDefault());
		}
		if(data.getPropFunction()!=null){
			this.setAttributeFunction(data.getPropFunction());
		}
		if(data.getPropType()!=null){
			this.setAttributeType(data.getPropType());
		}
	}
	
}
